package com.mall.controller;

import com.mall.common.resp.ResponseResult;
import com.mall.dao.custom.CtCategoryMapper;
import com.mall.entity.Category;
import com.mall.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author xyl
 * @date 2021-02-10 16:40
 */

@Api(tags = "商品分类接口 , 暂时不用了， 分类已经固定了")
@ApiIgnore
@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation("添加. 管理员权限")
    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("add")
    public ResponseResult add(@RequestBody Category category){
        return ResponseResult.toResponse(categoryService.add(category));
    }

    @ApiOperation("列表")
    @GetMapping("list")
    public ResponseResult<List<Category>> list(){
        return new ResponseResult<>(categoryService.getAll());
    }

    @ApiOperation("移除. 可删除多个,或者一个.  参数例如 1,2,3.  管理员权限")
    @PreAuthorize("hasRole('ADMIN')")
    @DeleteMapping("remove")
    public ResponseResult remove(String ids){
        return ResponseResult.toResponse(categoryService.removeByIds(ids));
    }
}
